﻿using System;
using System.Web;
using CTS.Com.Domain.Constants;
using CTS.Com.Domain.Helper;
using CTS.Com.Domain.Model;

namespace CTS.Web.Com.Domain.Helper
{
    public static class WebContextHelper
    {
        public static Guid UserCd { get { return UserContext.UserCd; } }
        public static string UserName { get { return UserContext.UserName; } }
        public static string LocaleCd
        {
            get
            {
                var strLocaleCd = HttpContext.Current.Request["lang"];
                if (DataCheckHelper.IsNull(strLocaleCd))
                    strLocaleCd = Convert.ToString(HttpContext.Current.Session["lang"]);
                if (DataCheckHelper.IsNull(strLocaleCd))
                    strLocaleCd = Convert.ToString(UserContext.LocaleCd);
                if (DataCheckHelper.IsNull(strLocaleCd))
                    strLocaleCd = Logics.LOCALE_DEFAULT;
                var localeCd = DataHelper.ConvertInputString(strLocaleCd);
                return localeCd;
            }
        }

        public static UserContext UserContext
        {
            get
            {
                var userContext = new UserContext();
                var ctx = HttpContext.Current.Session["CTS.Web.Com.UserContext"];
                if (ctx != null && ctx.GetType() == typeof(UserContext)) {
                    userContext = (UserContext)ctx;
                }

                return userContext;
            }
            internal set { HttpContext.Current.Session["CTS.Web.Com.UserContext"] = value; }
        }

        public static void ClearUserContext()
        {
            UserContext = null;
        }
    }
}
